<!-- 今日作业 -->
<script lang="ts" setup>
import { whManagerBsTbRiskHazardsSpecialGetPageUsingPost,whManagerBsTbRiskHazardsHandleGetPageUsingPost,whManagerBsTbEqpCheckGetPageUsingPost } from '@/genapi/wh';
import { useUserStore } from '@/stores/user';
import { onMounted, ref } from 'vue';
import { useRouter } from "vue-router";


defineOptions({ name: 'TodayWork' });

const router = useRouter();
const userStore = useUserStore();
let tableType = ref('todayWork')
let todayData = ref([])
let hideManagerData = ref([])
let majorHazardData = ref([])
const getTodayData = async() => {
  tableType.value = 'todayWork'
  let res = await whManagerBsTbRiskHazardsSpecialGetPageUsingPost({
          data: {
            query: {
              enterpriseId: userStore.userInfo?.systemUser?.relatedId,
            },
          },
        });
  todayData.value = res.data?.records
}
const gethideManagerData = async() => {
  tableType.value = 'hideManager'
  let res = await whManagerBsTbRiskHazardsHandleGetPageUsingPost({
          data: {
            query: {
              enterpriseId: userStore.userInfo?.systemUser?.relatedId,
            },
          },
        });
        hideManagerData.value = res.data?.records
}
const getmajorHazardData = async() => {
  tableType.value = 'majorHazard'
  let res = await whManagerBsTbEqpCheckGetPageUsingPost({
          data: {
            query: {
              enterpriseId: userStore.userInfo?.systemUser?.relatedId,
            },
          },
        });
        majorHazardData.value = res.data?.records
}
const getSupervisionStatus = (status) => {
  if(status === '1'){
    return '待复查'
  }else if(status === '2'){
    return '待整改'
  }else if(status === '3'){
    return '逾期未整改'
  }else{
    return '已完成'
  }
}
const getTaskType = (status) => {
  if(status === '1'){
    return '动火作业'
  }else if(status === '2'){
    return '受限空间作业'
  }else if(status === '3'){
    return '盲板抽堵作业'
  }else if(status === '4'){
    return '高处作业'
  }else if(status === '5'){
    return '吊装作业'
  }else if(status === '6'){
    return '临时用电作业'
  }else if(status === '7'){
    return '动图作业'
  }else{
    return '断路作业'
  }
}
const getTaskStatus = (status) => {
  if(status === '1'){
    return '待施工'
  }else if(status === '2'){
    return '施工中'
  }else if(status === '3'){
    return '已验收'
  }
}
const more = () => {
  if (tableType.value === "todayWork") {
		router.replace("/company/hidden-danger/report");
	} else if (tableType.value === "hideManager") {
		router.replace("/company/hidden-danger/rectify");
	} else {
		router.replace("/company/hidden-danger/device");
	}
}
onMounted(() => {
  getTodayData()
})
</script>

<template>
  <div bg="#fff" flex="~ col" p="x-30px t-24px b-12px" of="hidden">
    <div flex="~ justify-between" text="#303133 20px" font="bold" pb="12px">
      <span>今日作业</span>
    </div>
    <div flex="~">
      <el-button text :type="tableType === 'todayWork'? 'primary':''" @click="getTodayData">今日特殊作业</el-button>
      <el-button text :type="tableType === 'hideManager'? 'primary':''" @click="gethideManagerData">隐患整改</el-button>
      <el-button text :type="tableType === 'majorHazard'? 'primary':''" @click="getmajorHazardData">装置开停车和大检修</el-button>
      <div flex="1 ~ justify-end" p="b-12px">
        <el-button text un-text="#409EFF!" @click="more">
          查看更多
          <el-icon class="i-material-symbols:chevron-right-rounded" text="26px!" />
        </el-button>
      </div>
    </div>
    <el-table border :data="todayData" v-if="tableType === 'todayWork'">
      <el-table-column label="作业类型" prop="taskType" v-slot="{ row }">
        {{ getTaskType(row.taskType) }}
      </el-table-column>
      <el-table-column label="区域/地点" prop="longitude" v-slot="{ row }">
        经度{{ row.longitude }}纬度{{ row.latitude }}
      </el-table-column>
      <el-table-column label="实施时间" prop="handleTime" />
      <el-table-column label="作业负责人" prop="taskMaster" />
      <el-table-column label="验收人" prop="sceneMaster" />
      <el-table-column label="作业状态" prop="taskStatus"  v-slot="{ row }">
        {{ getTaskStatus(row.taskStatus) }}
      </el-table-column>
    </el-table>
    <el-table border :data="hideManagerData" v-if="tableType === 'hideManager'">
      <el-table-column label="隐患级别" prop="level" v-slot="{ row }">
        {{ row.level === '1'? '一般隐患':'重大隐患' }}
      </el-table-column>
      <el-table-column label="隐患描述" prop="description"/>
      <el-table-column label="上报时间" prop="reportTime" />
      <el-table-column label="整改期限" prop="handlePlanStartDate" v-slot="{ row }">
        {{ row.handlePlanStartDate }}--{{ row.handlePlanEndDate }}
      </el-table-column>
      <el-table-column label="复查日期" prop="checkDate" />
      <el-table-column label="复查部门" prop="checkDept" />
      <el-table-column label="整改状态" prop="supervisionStatus" v-slot="{ row }">
        {{ getSupervisionStatus(row.supervisionStatus) }}
      </el-table-column>
    </el-table>
    <el-table border :data="majorHazardData" v-if="tableType === 'majorHazard'">
      <el-table-column label="类别" prop="type" v-slot="{ row }">
        {{ row.type === '1'? '装置开停车':'大检修' }}
      </el-table-column>
      <el-table-column label="检修期限" prop="checkTimeStart" v-slot="{ row }">
        {{ row.checkTimeStart }}--{{ row.checkTimeEnd }}
      </el-table-column>
      <el-table-column label="方案" prop="checkPlan" />
      <el-table-column label="状态" prop="status" v-slot="{ row }">
        {{ row.status === '1'? '正常':'冲突预警' }}
      </el-table-column>
    </el-table>
    <div p="t-12px" flex="~ justify-end">
      <el-button un-size="32px!">
        <el-icon class="i-material-symbols:chevron-left-rounded" />
      </el-button>
      <el-button un-size="32px!">
        <el-icon class="i-material-symbols:chevron-right-rounded" />
      </el-button>
    </div>
  </div>
</template>
